package top.haijunit.work.controller.demo;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.haijunit.work.core.doamin.Result;
import top.haijunit.work.service.LockTestService;

/**
 * 【说明类功能】
 *
 * @author zhanghaijun
 * @since 2024-09-10
 */
@Slf4j
@RestController
@RequestMapping("/test/lock")
@ApiSupport(order = 3)
@Tag(name = "测试锁")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TestLockController {

    private final LockTestService lockService;

    @Operation(summary = "测试锁1", description = "测试@Lock4j")
    @GetMapping("/lock1")
    public Result<String> lock1() {
        return Result.success(lockService.lock1(2000));
    }

    @Operation(summary = "测试锁2", description = "测试keyBuilderStrategy、failStrategy")
    @GetMapping("/lock2")
    public Result<String> lock2() {
        return Result.success(lockService.lock2(2000));
    }

    @Operation(summary = "测试锁3", description = "测试acquireTimeout、expire")
    @GetMapping("/lock3")
    public Result<String> lock3() {
        return Result.success(lockService.lock3(100));
    }

    @Operation(summary = "测试锁4", description = "测试autoRelease=false")
    @GetMapping("/lock4")
    public Result<String> lock4() {
        return Result.success(lockService.lock4(100));
    }
}
